<?php
	class categoryControl extends commonControl{
		function index(){
			$db = M("category");
	        $category = $db->field("catid,cname,category.sort,pid")->all();
	        $category = arr::channel($category, "catid", "pid", 0,0, 2, "&nbsp;&nbsp;&nbsp;&nbsp;");
	        $this->assign("category", $category);
	        $this->display();
		}
		function add_show(){
	        $this->display();
		}
		function add() {
	        $db = M("category");
	        if ($db->add()) {
	            $this->success("添加栏目成功", "index");
	        } else {
	            $this->error("添加栏目失败");
	        }
    	}
    	function edit_show() {
	        $db = M("category");
	        $catid = $_GET['catid'];
	        $field = $db->find($catid);
	        //分配变量
	        $this->assign("field", $field);
	        $this->display();
    	}
    	function edit(){
	        $db = M("category");
	        if ($db->save()) {
	            $this->success("添加栏目成功", "index");
	        } else {
	            $this->error("添加栏目失败");
	        }
    	}
    	function del(){
    		$catid = $_GET['catid'];
	        $db = M("category");
	        $result = $db->where("pid='$catid'")->find();
	        if ($result) {
	            $this->error("请先删除子目录");
	        } else {
	            if ($db->del($catid)) {
	                $this->success("删除栏目成功");
	            } else {
	                $this->error("删除栏目失败，请重试");
	            }
	        }
    	}
		function selecttemplate() {
	        C("debug", 0);
	        $path = C("template_dir") . '/' . C("template_style");
	        $files = dir::tree($path, 'html');
	        $this->assign("tplpath", $path);
	        $this->assign("files", $files);
	        $this->display();
    	}









    	
	}
?>